import {MyDetail} from "../classes/MyUI.js";
import {generateElement} from "../functions/common.js";
import {DataCell} from "../component/DataCell2.js";
import {MyStorage} from "../component/MyStorage2.js";
import {MyConsole} from "../component/MyConsole2.js";
import {PageDetail, INode} from "../component/Process.js";
import Process from "../component/Process.js";
import {MyTable} from "../component/MyTable2.js";

// The info details on Virtual Memory.
// const detail = new MyDetail(
//     "虚拟存储系统",
//     [
//         "By Louis，2021-04-27；",
//         "这里展示的是最为通用的【请求分页存储管理系统】",
//         "内存分配策略，采用【固定分配局部置换】，为每个进程分配一定的物理块，在进程运行期间，将根据 LRU 算法进行换入和换出",
//         "此时页表项分别是（页号，物理块号，状态位P，访问字段A，修改位M，外存地址，LRU信息）"
//     ],
// );
// document.getElementById("detail").appendChild(detail.getElement());


// 系统区域的一些变量
let pages = [
    null, null, null, null, null, null, null, null,
    null, null, null, null, null, null, null, null,
];


// iNode 库的内容
let iNodes = {
    "01H": new INode("01H", "根目录", 0, [
        {fileName: "abc.exe", inode: "03H" },
        {fileName: "aki", inode: "07H" },
    ])
};


// disk 的库
let diskBlocks = {
    "00H": new PageDetail(-1),
};
// 磁盘空闲块的链表
let freeDiskBlocksList = [];
// 生成 disk 的内容
for (let i = 1;i<30;i++){
    if (i<10){
        diskBlocks[" " + String(i) + "H"] = new PageDetail(-1);
        freeDiskBlocksList.push(" " + String(i) + "H");
    } else {
        diskBlocks[String(i) + "H"] = new PageDetail(-1);
        freeDiskBlocksList.push(String(i) + "H");
    }
}


// 系统的 pid 分配表
let pid_save = 1;

// 焦点进程
let currentProcess = null;
// 就绪进程序列
let waitingProcess = [];
// 系统打开文件表
let systemFileTable = new MyTable();
document.getElementById("file_table").appendChild(systemFileTable.getElement());
systemFileTable.init();
systemFileTable.addTHeadTh("id");
systemFileTable.addTHeadTh("文件路径");
systemFileTable.addTHeadTh("inode 外存地址");
systemFileTable.addTHeadTh("inode 内存地址");
systemFileTable.addTHeadTh("锁信息");
systemFileTable.addTHeadTh("共享进程数");



// 空闲链表数据和变量
let freePageLinkedList = ["01H", "02H", "03H", "04H", "05H", "06H", "07H", "08H"];
let freePageDomObjLinkedList = [];
let returnValue = "";


// 空闲链表需要保存的 DOM 元素
let freeListInnerTrack = document.getElementById("innerTrack");
// 页表部分需要保存的 DOM 元素
let pageTableDiv = document.getElementById("pageTableDiv");
let pageTableBody = document.getElementById("pageTableBody");
let pageTableRows = pageTableBody.getElementsByTagName("tr");
// 内容展示页需要保存的 DOM 元素
let pageDiv = document.getElementById("pageDiv");
// 右侧需要保存的 system_right
let system_right = document.getElementById("system_right");
let right_modules = document.getElementById("right_modules");


// 动画：空闲列链表pop：free list pop：向右移除最开始的一个块
const freeListPop = () => {
    if (freePageLinkedList.length === 0){
        returnValue = "";
        return;
    }
    returnValue = freePageLinkedList.shift();
    console.log("returnValue 更新为", returnValue);
    let first = freePageDomObjLinkedList.shift();
    anime({
        targets: first,
        translateX: 270,
        easing: 'easeInOutSine',
        duration: 400,
        complete: function (e) {
            console.log("completeFunction:", e);
            freeListInnerTrack.removeChild(first);
            circleFun();
        }
    });
};


// 动画：空闲列链表 moveBegin：free list begin：链表移动到最开始
const freeListBegin = () => {
    anime({
        targets: freeListInnerTrack,
        translateY: 0,
        easing: 'easeInOutSine',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    });
};


// 动画：空闲列链表 moveEnd：free list end：链表移动到最后一位
const freeListEnd = () => {
    let distance = freePageLinkedList.length-1;
    anime({
        targets: freeListInnerTrack,
        translateY: - distance * 20,
        easing: 'easeInOutSine',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    });
};


// 动画：空闲列链表 append：free list append {pageId}：链表最后添加一个元素
const freeListAppendPageId = (pageId) => {
    freePageLinkedList.push(pageId);
    let newElem = generateElement({
        type: "div",
        innerText: pageId,
        height: "18px",
        backgroundColor: "#5FB878",
        margin: "2px"
    });
    freePageDomObjLinkedList.push(newElem);
    freeListInnerTrack.appendChild(newElem);
    anime({
        targets: newElem,
        translateX: 270,
        direction: 'reverse',
        easing: 'easeInOutSine',
        duration: 400,
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    });
};


// 动画：空闲链表初始化init：free list init：就是循环执行 append 的过程
const freeListInit = () => {
    for (let mark=0;mark<freePageLinkedList.length;mark++){
        cmdQueue.push("free list append " + freePageLinkedList[mark]);
    }
    circleFun();
};


// 虚拟机设计部分
let cmdQueue = [];


// 这是每个动画的回调函数
const circleFun = () => {
    if (cmdQueue.length>0){
        console.log("还有指令需要执行");
        let cmd = cmdQueue.shift();
        parseCmd(cmd)
    }else {
        console.log("没有指令需要执行了");
    }
};


// 解析指令
const parseCmd = (cmd) => {
    cmd = cmd.trim();
    console.log("parseCmd", cmd);
    if (typeof cmd === "string" && cmd.startsWith("free list")){
        if (cmd.startsWith("free list pop")) {
            freeListPop();
        } else if (cmd.startsWith("free list begin")){
            freeListBegin()
        } else if (cmd.startsWith("free list end")){
            freeListEnd();
        } else if(cmd.startsWith("free list init")){
            freeListInit();
        } else if(cmd.startsWith("free list append")){
            // 测试用例：free list append 12
            console.log("free list append");
            cmd = cmd.substring(17, cmd.length);
            console.log("pageId", cmd);
            freeListAppendPageId(cmd);
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("page table")){
        if (cmd.startsWith("page table open")){
            pageTableOpen();
        } else if (cmd.startsWith("page table close")){
            pageTableClose();
        }else if (cmd.startsWith("page table highlight")){
            let rowId = cmd.substring(21, cmd.length);
            console.log("rowId", rowId);
            highLightPageTable(parseInt(rowId, 10));
        } else if (cmd.startsWith("page table blockId")){
            let input = cmd.substring(19, cmd.length);
            let strList = input.split(" ");
            console.log("strList", strList, input);
            pageTableBlockId(parseInt(strList[0], 10), strList[1]);
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("page div")){
        if (cmd.startsWith("page div open")){
            pageDivOpen();
        } else if (cmd.startsWith("page div close")){
            pageDivClose();
        } else if (cmd.startsWith("page div write")){
            let input = cmd.substring(15, cmd.length);
            let inputArray = input.split(" ");
            console.log(inputArray);
            pageDivWrite(parseInt(inputArray[0], 10), inputArray[1]);
        } else if (cmd.startsWith("page div move")){
            let input = cmd.substring(14, cmd.length);
            pageDivMove(parseInt(input, 10));
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("pcb")){
        if (cmd.startsWith("pcb pc")){
            let input = cmd.substring(7, cmd.length);
            pcbPc(input);
        }else if (cmd.startsWith("pcb ir")){
            let input = cmd.substring(7, cmd.length);
            pcbIr(input);
        } else if (cmd.startsWith("pcb v")){
            let input = cmd.substring(6, cmd.length);
            pcbV(input);
        }else if (cmd.startsWith("pcb r")){
            let input = cmd.substring(6, cmd.length);
            pcbR(input);
        }else if (cmd.startsWith("pcb pid")){
            let input = cmd.substring(8, cmd.length);
            pcbPID(input);
        }else if (cmd.startsWith("pcb old")){
            let input = cmd.substring(8, cmd.length);
            pcbOldPc(input);
        }else if (cmd.startsWith("pcb state")){
            let input = cmd.substring(10, cmd.length);
            pcbState(input);
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("slide")){
        if (cmd.startsWith("slide process space")){
            slideToProcessSpace();
        }else if (cmd.startsWith("slide pc")){
            slideToPC();
        } else if (cmd.startsWith("slide process file")){
            slideToProcessFile();
        }else if (cmd.startsWith("slide system block")){
            slideToSystemBlock();
        }else if (cmd.startsWith("slide system file")){
            slideToSystemFile();
        }else if (cmd.startsWith("slide system super")){
            slideToSystemSuper();
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("system")){
        if (cmd.startsWith("system file path")){
            let input = cmd.substring(17, cmd.length);
            systemFilePath(input);
        }else if (cmd.startsWith("system process pop")){
            systemPopWaitingProcess();
        }else if (cmd.startsWith("system file table insert")){
            // system file table insert {filePath}
            // id, filePath, outerINode, innerINode, lock, share
            systemFileTableInsert({
                filePath: cmd.substring(24, cmd.length),
                innerINode: "NULL",
                outerINode: "NULL",
                lock: "X",
                share: 1
            })
        }else if (cmd.startsWith("system start")){
            systemStart(cmd.substring(12, cmd.length));
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("run")){
        if (cmd.startsWith("run mov")){
            // run mov 0102H 02H
            let input1 = cmd.substring(8, 13);
            let input2 = cmd.substring(14, cmd.length);
            runMove(input1, input2)
        }
    }
    if (typeof cmd === "string" && cmd.startsWith("refresh")){
        if (cmd.startsWith("refresh process")){
            refreshProcessManagement();
        }else if (cmd.startsWith("refresh current")){
            currentProcess = null;
            circleFun();
        }
    }
};

// 进入页面后自动执行；
freeListInit();


// 动画：页表展开：page table open
const pageTableOpen = () => {
    // 需要设置当前页表的内容
    console.log("pageTableOpen");
    if (currentProcess!==null && currentProcess instanceof Process){
        let trList = pageTableBody.getElementsByTagName("tr");
        let pageTable = currentProcess.pageTable;
        for (let i = 0;i<4;i++){
            let tdList = trList[i].getElementsByTagName("td");
            tdList[0].innerText = pageTable[i].pageId;
            tdList[1].innerText = pageTable[i].blockId;
            tdList[2].innerText = pageTable[i].P;
            tdList[3].innerText = pageTable[i].A;
            tdList[4].innerText = pageTable[i].M;
            tdList[5].innerText = pageTable[i].outer;
            tdList[6].innerText = pageTable[i].LRU;
        }
        pageTableRows = pageTableBody.getElementsByTagName("tr");
    }
    anime({
        targets: pageTableDiv,
        easing: 'easeInOutQuad',
        height: "360px",
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：页表关闭：page table close
const pageTableClose = () => {
    anime({
        targets: pageTableDiv,
        easing: 'easeInOutQuad',
        height: "0px",
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：内容页展开：page div open
const pageDivOpen = () => {
    // 需要先将内容进行渲染
    anime({
        targets: pageDiv,
        easing: 'easeInOutQuad',
        width: "178px",
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：内容页关闭：page div close
const pageDivClose = () => {
    anime({
        targets: pageDiv,
        easing: 'easeInOutQuad',
        width: "0px",
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：内容页面内更换数据：page div write 2 02H
const pageDivWrite = (address, dataValue) => {
    storage.writeData(address, dataValue, ()=>{
        console.log("completeFunction:");
        circleFun();
    })
};


// 动画：移动到某一个地方：page div move
const pageDivMove = (num) => {
    storage.animeMoveFind(num, ()=>{
        console.log("completeFunction:");
        circleFun();
    })
};


// 动画：高亮显示某一行：page table highlight {rowId} 并在右侧显示箭头
const highLightPageTable = (rowId) => {
    console.log("highLightPageTable", rowId);
    if (typeof rowId === "number" && rowId > 0 && rowId < 4){
        // 还是不显示箭头了，这个定位比较麻烦
        anime({
            targets: pageTableRows[rowId],
            backgroundColor: "#FFB800",
            complete: function (e) {
                console.log("completeFunction:", e);
                circleFun();
            }
        });
    }
};

// 动画：更改页表某一行的 page table blockId {rowId} {value}
const pageTableBlockId = (pageId, value) => {
    // 更改信息和表中的具体的值
    currentProcess.pageTable[pageId].blockId = returnValue;
    console.log("pageTableRows", pageTableRows, pageId);
    let chooseOne = pageTableRows[pageId];
    console.log("chooseOne", chooseOne);
    let tds = chooseOne.getElementsByTagName("td");
    tds[1].innerText = returnValue;
    setTimeout(()=>{
        circleFun();
    }, 1000)
};


// PCB 部分数值对象的创建
let PCB_PC = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_IR = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_V = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_R = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_PID = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_State = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let PCB_oldPc = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});
let filePath = new DataCell("NULL", {
    // width: "100px",
    height: "20px",
    lineHeight: "20px",
    backgroundColor: "#5FB878",
    color: "white",
    padding: "0 5px"
});


document.getElementById("PCB_PC").appendChild(PCB_PC.getElement());
document.getElementById("PCB_IR").appendChild(PCB_IR.getElement());
document.getElementById("PCB_VAddress").appendChild(PCB_V.getElement());
document.getElementById("PCB_realAddress").appendChild(PCB_R.getElement());
document.getElementById("PCB_PID").appendChild(PCB_PID.getElement());
document.getElementById("PCB_State").appendChild(PCB_State.getElement());
document.getElementById("PCB_oldPc").appendChild(PCB_oldPc.getElement());
document.getElementById("file_path").appendChild(filePath.getElement());
PCB_PC.init();
PCB_IR.init();
PCB_V.init();
PCB_R.init();
PCB_PID.init();
PCB_State.init();
PCB_oldPc.init();
filePath.init();


// 动画：改变 PCB 当中 PC、IR、V、R 的值：PCB PC {num}
const pcbPc = (new_value) => {
    PCB_PC.changeValue(new_value.toString());
};
const pcbIr = (new_value) => {
    PCB_IR.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const pcbV = (new_value) => {
    PCB_V.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const pcbR = (new_value) => {
    PCB_R.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const pcbPID = (new_value) => {
    PCB_PID.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const pcbState = (new_value) => {
    PCB_State.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const pcbOldPc = (new_value) => {
    PCB_oldPc.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};
const systemFilePath = (new_value) => {
    console.log("systemFilePath", new_value);
    filePath.changeValue(new_value.toString(), ()=>{
        console.log("completeFunction:");
        circleFun();
    });
};


// 动画：移动到“进程空间”处：slide process space
const slideToProcessSpace = () => {
    let process_module = document.getElementById("process_module");
    let distance = process_module.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};
// slideToProcessSpace();


// 动画：移动到“PC寄存器值”处：slide pc
const slideToPC = () => {
    let process_module_header = document.getElementById("process_module_header");
    let distance = process_module_header.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：移动到“进程文件打开表”处：slide process file
const slideToProcessFile = () => {
    let process_module_file_table = document.getElementById("process_module_file_table");
    let distance = process_module_file_table.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：移动到“系统区”：slide system block
const slideToSystemBlock = () => {
    let OS_module = document.getElementById("OS_module");
    let distance = OS_module.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：移动到“系统打开文件表”：slide system file
const slideToSystemFile = () => {
    let system_file = document.getElementById("system_file");
    let distance = system_file.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 动画：移动到“超级块”区域：slide system super
const slideToSystemSuper = () => {
    let disk_management = document.getElementById("disk_management");
    let distance = disk_management.getBoundingClientRect().top - right_modules.getBoundingClientRect().top;
    console.log(distance);
    anime({
        targets: right_modules,
        translateY: - distance,
        easing: 'easeInOutQuad',
        complete: function (e) {
            console.log("completeFunction:", e);
            circleFun();
        }
    })
};


// 存储的代码
let storage = new MyStorage(16);
document.getElementById("pageDiv").appendChild(storage.getElement());
storage.init();


// 控制台组件的加入
let myConsole = new MyConsole();
document.getElementById("console").appendChild(myConsole.elem);
myConsole.init((input)=>{
    try {
        parseCmd(input);
    }catch (e) {
        console.log(e)
    }
});


// 运行一个进程，从就绪队列当中的第一个进程进行运行：system process pop
const systemPopWaitingProcess = () => {
    console.log("systemPopWaitingProcess");
    if (waitingProcess.length > 0){
        currentProcess = waitingProcess.shift();
        let replaceCmdQueue = [];
        replaceCmdQueue.push("slide system block");
        replaceCmdQueue.push("refresh process");
        replaceCmdQueue.push("slide pc");
        replaceCmdQueue.push("page table open");
        cmdQueue = replaceCmdQueue.concat(cmdQueue);
        circleFun();
    }else {
        console.log("就绪队列当中没有任何程序")
    }
};


// 在进程环境下进行单位赋值: run mov {address} {value}：run mov 0102H 02H
const runMove = (address, value) => {
    if (currentProcess === null){
        console.log("当前没有在运行的进程，无法在进程环境下执行");
        return;
    }
    let pageIdStr = address.substring(0, 2);
    let pageId = parseInt(pageIdStr, 10);
    let addressStr = address.substring(2, 5);
    let addressInPage = parseInt(addressStr, 16);
    console.log("runMove", address, value, pageId, addressInPage);
    let replaceList = [];
    replaceList.push("slide pc");
    replaceList.push("pcb ir run mov " + address + " " + value);
    replaceList.push("pcb v "+ address);
    replaceList.push("page table open");
    replaceList.push("page table highlight " + pageId);
    // 如果这一行并没有分配内存，则对其进行分配内存
    let pageTable = currentProcess.pageTable;
    let chooseOne = pageTable[pageId];
    if (chooseOne.outer==="NULL" && chooseOne.blockId === "NULL"){
        replaceList.push("free list pop");
        // chooseOne.blockId = returnValue;
        replaceList.push("page table blockId " + String(pageId) + " " + String(returnValue));
    }
    // 最后都需要打开对应的页
    let realPageId = chooseOne.blockId;
    console.log("realPageId", realPageId);
    let realPageIdInt = parseInt(realPageId, 16);
    if (pages[realPageIdInt]===null){
        pages[realPageIdInt] = new PageDetail(realPageIdInt);
    }
    // 进行展示
    storage.update(pages[realPageIdInt]);
    replaceList.push("page div open");
    replaceList.push("page div move " + String(addressInPage));
    replaceList.push("page div write " + String(addressInPage) + " " + value);
    cmdQueue = replaceList.concat(cmdQueue);
    console.log("runMove: cmdQueue", cmdQueue);
    circleFun();
};


// 动画：刷新进程管理部分的所有内容：refresh process
const refreshProcessManagement = () => {
    console.log("refreshProcessManagement");
    let runningProcessSpan = document.getElementById("runningProcess");
    let waitingProcessSpan = document.getElementById("waitingProcess");
    let blockingProcessSpan = document.getElementById("blockingProcess");
    runningProcessSpan.innerHTML = "";
    waitingProcessSpan.innerHTML = "";
    blockingProcessSpan.innerHTML = "";
    if (currentProcess && currentProcess instanceof Process){
        runningProcessSpan.appendChild(generateElement({
            type: "span",
            innerText: currentProcess.pid,
            border: "1px solid black",
            marginLeft: "10px",
        }))
    }
    if (waitingProcess.length > 0){
        for (let i = 0;i<waitingProcess.length;i++){
            waitingProcessSpan.appendChild(generateElement({
                type: "span",
                innerText: waitingProcess[i].pid,
                border: "1px solid black",
                width: "20px",
                marginLeft: "10px",
            }))
        }
    }
    setTimeout(()=>{
        circleFun();
    }, 1000);
};

// 动画：在系统文件打开表当中插入一条内容：system file table insert {filePath}
const systemFileTableInsert = ({ filePath, outerINode, innerINode, lock, share}) => {
    systemFileTable.insertTr([ filePath, outerINode, innerINode, lock, share], ()=>{
        circleFun();
    });
};

// 根据路径启动一个进程：system start {filePath}
const systemStart = (filePath) => {
    let replaceList = [];
    currentProcess = new Process(pid_save++);
    waitingProcess.unshift(currentProcess);
    // 将 PCB 上的信息填好
    replaceList.push("slide process space");
    replaceList.push("pcb pid "+ String(pid_save));
    replaceList.push("pcb state 启动态");
    // 寻找对应的文件
    replaceList.push("slide system file");
    replaceList.push("system file table insert " + filePath);
    replaceList.push("slide system super");
    replaceList.push("system file path " + filePath);
    // 寻址完成，接下来刷新进程管理部分，新进程在等待队列第一个
    replaceList.push("refresh current");
    replaceList.push("refresh process");
    // 移动到最开始的系统区域
    replaceList.push("slide system block");
    // 执行就绪队列第一个进程
    replaceList.push("system process pop");
    cmdQueue = replaceList.concat(cmdQueue);
    circleFun();
};